package com.lulin.mall.auth.server.config;

import com.lulin.common.constant.AuthConstant;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * @author lulin
 * @date 2022/12/13 14:45
 */
@Configuration
public class MySessionConfig {

    /**
     * 自定义Cookie的配置
     */
    @Bean
    public CookieSerializer cookieSerializer(){
        DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();
        cookieSerializer.setDomainName("lulin.com"); // 设置session对应的一级域名
        cookieSerializer.setCookieName(AuthConstant.AUTH_SESSION_REDIS);//cookie的名字
        return cookieSerializer;
    }

    /**
     * 对存储在Redis中的数据，指定序列化的方式
     */
    @Bean
    public RedisSerializer<Object> redisSerializer() {
        return new GenericJackson2JsonRedisSerializer();
    }
}
